<?php

function logOutput($data) {
    //数据类型检测
    if (is_array($data)) {
        $data = json_encode($data);
    }
    $filename = "/api/log/".date("Y-m-d").".log";
    $str = date("Y-m-d H:i:s")."   $data"."\n";
    file_put_contents($filename, $str, FILE_APPEND|LOCK_EX);
    return null;
}


$type = $_POST['type'];
$data = '';

//logOutput("收到请求");        // 影响 json 输出

if (isset($type) && is_numeric($type) && $type >= 0) {
    if ($type == 1) {
        $data = array(
            'type' => $type,
            'name' => '标哥的技术博客',
            'site' => 'www.huangyibiao.com');
    } else if ($type == 2) {
        $data = array(
            'type' => $type,
            'name' => '公众号：标哥的技术博客',
            'site' => 'weixin search: biaogedejishuboke');
    }

    $response = array(
        'code'  => 200,
        'message' => 'success for request',
        'data'  => $data,
    );
    exit(json_encode($response));
}

$response = array(
    'code'  => 999,
    'message' => 'argument error for request',
    'data'  => $data,
);

echo json_encode($response);
